<?php

namespace Common\Model;

/**
 * VipInitModel.class.php实例模型
 *
 * @author zhangzhen
 * @date 2017-2-15
 */
class VipInitModel extends BaseModel {

    protected $trueTableName = 'tb_vip_init';

    protected function _before_insert(&$data, $options) {
        //$data['creator'] = getUserId();
    }

    protected function _before_update(&$data, $options) {
        //parent::_before_update($data, $options);
    }

    /**
     * 返回用户数据
     * @modify zhangzhen 2017-02-15    获取掌柜的会员初始化信息
     * @param integer $userId 用户ID
     * @return type
     */
    public function getInfoByAdmin($userId) {
        $option = [
            'adminlogin_id'=> $userId,
        ];
        $field = 'id,adminlogin_id,share,level,discount';
        $data = $this->field($field)->where($option)->find();

        return empty($data) ? array() : $data;
    }

    /**
     *
     * 添加用户数据
     * @modify zhangzhen 2017-02-15
     * @param integer $userId  用户ID
     * @param string $level  升级
     * @param string $share  分享
     * @param string $discount  打折
     * @return type
     */
    public function addInfo($userId, $level, $share, $discount) {
        $options = [
            'adminlogin_id' => $userId,
            'share' => $share,
            'level' => $level,
            'discount' => $discount
        ];
        return $this->add($options);
    }
}
